import { _decorator, Component, Node, Label, Sprite, clamp } from 'cc';
import { BasicUI } from '../../Init/Basic/BasicUI';
import { EventTypes } from '../../Init/Managers/EventTypes';
import { AudioEnum } from '../../Init/SystemAudio/AudioEnum';
import { AudioSystem } from '../../Init/SystemAudio/AudioSystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
import { UISystem } from '../../Init/SystemUI/UISystem';
import { Adsdk } from '../../myScript/Adsdk';
const { ccclass, property } = _decorator;

@ccclass('LvupPopUI')
export class LvupPopUI extends BasicUI {

    @property(Label)
    protected infoLabel: Label = null;

    @property(Node)
    protected iconLayer: Node = null;

    _successCb = null;
    _failCb = null;

    public show(d: { type: number, successCb: Function, failCb: Function }) {
        super.show();
        this._successCb = d.successCb;
        this._failCb = d.failCb;

        this.setInfo(d.type);

        Adsdk.instance.hideAllAd();
        Adsdk.instance.showInterstitialAd();
        Adsdk.instance.showBanner();
        Adsdk.instance.showGridAdTop();
    }

    infoArr = ['生命', '速度', '帮手'];
    public setInfo(type) {
        type = clamp(type, 0, 2);
        this.infoLabel.string = '免费获得' + this.infoArr[type];

        for (let i = 0; i < this.iconLayer.children.length; i++) {
            const e = this.iconLayer.children[i];
            e.active = type == i;
        }
    }

    public hide() {
        super.hide();
        this._failCb && this._failCb();
        this._failCb = null;
    }

    protected onCloseClick() {
        AudioSystem.playEffect(AudioEnum.BtnClick);
        UISystem.hideUI(UIEnum.LvupPopUI);

        Adsdk.instance.hideAllAd();

    }

    protected onStartGame() {
        AudioSystem.playEffect(AudioEnum.BtnClick);
        //视频
        this.emit(EventTypes.SDKEvents.ShowVideo, {
            success: () => {
                //获得奖励
                this._successCb && this._successCb();
                this._successCb = null;
                //直接进入游戏
                this.emit(EventTypes.UIEvents.EnterGame);
                UISystem.hideUI(UIEnum.LvupPopUI);
            },
            fail: () => {
            },
            cancel: () => {
            },
        })

    }
}

